package com.quickthumb.game;

import javax.microedition.khronos.opengles.GL10;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.util.FloatMath;

public class Powerups implements UpdateAndDraw {
	public static int green_counter, score_multiply;
	public static int blue_counter;
	public static int red_counter, score_enable;
	public static int black_counter;

	@Override
	public void init() {
		blue_counter = 0;
		green_counter = 0;
		score_multiply = 1;
		red_counter = 0;
		score_enable = 1;
		black_counter = 0;
	}

	@Override
	public void update() {
		// green
		if (green_counter <= 0)
			score_multiply = 1;
		else
			green_counter--;
		// blue
		if (blue_counter <= 0)
			;
		else
			blue_counter--;
		// red
		if (red_counter <= 0)
			score_enable = 1;
		else {
			red_counter--;
			green_counter = 0;
			blue_counter = 0;
			score_enable = 0;
		}
		// black
		if (black_counter <= 0)
			;
		else {
			// kill
			for (int i = 0; i < Screen.bucket.size(); i++)
				if (Screen.bucket.get(i).isAlive())
					if (!(Screen.bucket.get(i) instanceof RatKing) && !(Screen.bucket.get(i) instanceof RatShadow))
						Screen.bucket.get(i).kill();
			//
			black_counter--;
			score_enable = 1;
			red_counter = 0;
		}
	}

	@Override
	public void draw(Canvas c, Paint p) {
		c.save();
		// green
		if (score_multiply > 1) {
			p.setColor(Color.GREEN);
			p.setTextAlign(Align.RIGHT);
			c.drawText(score_multiply + "x       ", Screen.SCREEN_WIDTH, -p.ascent(), p);
		}
		// blue
		if (blue_counter > 0) {
			Player.time++;
			p.setColor(Color.BLUE);
			p.setTextAlign(Align.LEFT);
			c.drawText("   F", 0, -p.ascent(), p);
		}
		// red
		if (red_counter > 0) {
			p.setColor(Color.RED);
			p.setTextAlign(Align.RIGHT);
			c.drawText("x       ", Screen.SCREEN_WIDTH, -p.ascent(), p);
			if (Player.score > 0)
				Player.score--;
			else
				red_counter = 0;
		}
		// black
		if (black_counter > 0) {
			if (black_counter > 4 * 30)
				p.setARGB(256 - (black_counter - 4 * 30) * 255 / 30, 0, 0, 0);
			else if (black_counter < 1 * 30)
				p.setARGB(black_counter * 255 / 30, 0, 0, 0);
			else
				p.setARGB(255, 0, 0, 0);
			c.drawRect(0, 0, Screen.SCREEN_WIDTH, Screen.SCREEN_HEIGHT, p);
			p.setColor(Color.WHITE);
			p.setTextAlign(Align.CENTER);
			c.translate(Screen.BOARD_WIDTH / 2, Screen.BOARD_HEIGHT / 2);
			c.scale(2, 2);
			c.rotate(FloatMath.sin(black_counter) * 10);
			c.drawText("SHADOW", 0, 0, p);
		}
		c.restore();
	}

	@Override
	public void draw(GL10 gl) {
		// TODO Auto-generated method stub

	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub

	}

}
